<template>
  <!-- 用了一个行列布局 -->
  <el-row
    type="flex"
    justify="space-between"
    align="middle"
    style="width: 100%; height: 40px"
  >
    <el-col>
      <span>{{ treeData.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <!-- 两个内容 -->
        <el-col>{{ treeData.manager }}</el-col>
        <el-col>
          <!-- 下拉菜单 element -->
          <el-dropdown>
            <span> 操作<i class="el-icon-arrow-down" /> </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="$emit('openDialog',treeData.id)">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" @click.native="$emit('editDialog',treeData.id)">编辑部门</el-dropdown-item>
              <el-dropdown-item
                v-if="!isRoot"
                @click.native="delDepart"
              >删除部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <!-- el-dropdown没有为点击事件进行处理 -->
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delDepartmentApi } from '@/api/departments'
export default {
  name: 'TreeTools',
  props: {
    treeData: {
      type: Object,
      default: () => ({})
    },
    //   是否顶级
    isRoot: {
      type: Boolean,
      default: false
    }
  },

  methods: {
    async delDepart() {
      console.log(1)
      try {
        await this.$confirm('确认删除？')
        await delDepartmentApi(this.treeData.id)
        this.$emit('updateList')
        this.$message.success('删除成功')
      } catch (error) {
        console.log(error)
      }
    }
  }
}
</script>

<style></style>
